# @Version        : 1.0
# @Update Time    : 2025/8/22 20:07
# @File           : captcha_service.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息

from io import BytesIO
from typing import Tuple

from fastapi import Request
from user_agents import parse

from applications.utils.captcha import vieCode
from applications.utils.xdb_searcher import XdbSearcher
from applications.core.context_manager.track_utils import TrackContextUtils
from applications.models import LoginLog


def get_captcha() -> Tuple[BytesIO, str]:
    """
    生成验证码图片及其对应的验证码字符串。

    :return: 返回验证码图片的响应对象和验证码字符串。
    """
    image, code = vieCode().GetCodeImage()
    code = "".join(code).lower()
    out = BytesIO()
    image.save(out, "png")
    out.seek(0)
    return out, code
